/*
 * TelaAluguelCadastro.java
 *
 * Created on __DATE__, __TIME__
 */

package telas.aluguel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.swing.JOptionPane;
import business.aluguel.Aluguel;
import business.aluguel.Cliente;
import business.aluguel.Custo;
import business.aluguel.MotoristaAdicional;
import business.aluguel.PosicaoAluguel;
import business.aluguel.Veiculo;
import business.sistema.ExceptionSistema;
import business.sistema.IObjetoSistema;
import business.util.Menssagens;
import telas.componentes.Localizador;
import telas.comum.TelaDialogoCadastro;

/**
 *
 * @author  __USER__
 */
public class TelaAluguelCadastro extends TelaDialogoCadastro
{
	private static final long serialVersionUID = -2650326793080078181L;

	/** Creates new form TelaAluguelCadastro */
	public TelaAluguelCadastro(java.awt.Frame parent, boolean modal)
			throws Exception
	{
		super(parent, modal);
		initComponents();
	}

	public TelaAluguelCadastro(IObjetoSistema objeto, boolean novo)
			throws Exception
	{
		super(objeto, novo);
		initComponents();

		if (!novo)
		{
			setTitle("Alterar Contrato");
			preencherFormulario();
			verificarPosicaoAluguel();
		} else
		{
			setTitle("Cadastrar Contrato");
			jdcDataSaida.setDate(new Date());
			cgSituacao.setObjetoCorrente(PosicaoAluguel.ABERTO());
			ptFinalizarContrato.setEnabled(false);
		}

		eventoSalvar();
		eventoFechar();

		setVisible(true);
	}

	private void verificarPosicaoAluguel()
	{
		Aluguel aluguel = (Aluguel) getObjDados();

		boolean habilita = (aluguel.getPosicaoAluguel().getCodigo() == PosicaoAluguel.CODIGO_FECHADO);

		cplCliente.setEnabled(!habilita);
		btNovoCliente.setEnabled(!habilita);
		cplVeiculo.setEnabled(!habilita);
		cndQuilometragem.setEnabled(!habilita);
		jdcDataSaida.setEnabled(!habilita);
		jdcDataDevolucaoPrevista.setEnabled(!habilita);
		cndValorDiaria.setEnabled(!habilita);
		cndValorTotalDiarias.setEnabled(!habilita);
		btAdicionarMotorista.setEnabled(!habilita);
		btCadastrarNovoMotorista.setEnabled(!habilita);
		btRemoverMotorista.setEnabled(!habilita);
		cndValorMotoristaExtra.setEnabled(!habilita);
		btAdicionarCusto.setEnabled(!habilita);
		btRemoverCusto.setEnabled(!habilita);
		cndFranquia.setEnabled(!habilita);
		cndCustoTotal.setEnabled(!habilita);
		btCalcular.setEnabled(!habilita);
		cgFormaPagamento.setEnabled(!habilita);
		ctObservacao.setEnabled(!habilita);

		if (habilita)
		{
			ptFinalizarContrato.setText("Reabrir");
		} else
		{
			ptFinalizarContrato.setText("Finalizar");
		}

	}

	private void eventoFechar()
	{
		botBotoes.getBtFechar().addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				try
				{
					fecharTela();
				} catch (Exception ex)
				{
					new ExceptionSistema(ex);
				}
			}
		});
	}

	private void eventoSalvar()
	{
		botBotoes.getBtSalvar().addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				try
				{
					salvar();
					fecharTela();

				} catch (Exception ex)
				{
					new ExceptionSistema(ex);
				}
			}
		});
	}

	@Override
	public void limpaCadastro() throws Exception
	{
		//		cgSituacao.limpar();
		//		cplCliente.limpar();
		//		cplVeiculo.limpar();
		//		jdcDataSaida.setDate(null);
		//		jdcDataDevolucaoPrevista.setDate(null);
		//		jdcDataDevolucaoReal.setDate(null);
		//		cndValorMotoristaExtra.setText("0.0");
		//
		//		preencheTabelaMotoristas();
		//		preencheTabelaCustos();
		//
		//		cndCustoTotal.setText("0.0");
	}

	@Override
	public void preencheObjeto() throws Exception
	{
		String mensagem = "";
		Aluguel aluguel = (Aluguel) getObjDados();

		PosicaoAluguel posicaoAluguel = (PosicaoAluguel) cgSituacao
				.getObjetoCorrente();
		if (posicaoAluguel == null)
		{
			mensagem += "Situação " + Menssagens.itemObrigatorio;
		}

		Cliente cliente = (Cliente) cplCliente.getObjeto();
		if (cliente.getCodigo() == 0)
		{
			mensagem += "\nCliente " + Menssagens.itemObrigatorio;
		}

		Veiculo veiculo = (Veiculo) cplVeiculo.getObjeto();
		if (veiculo.getCodigo() == 0)
		{
			mensagem += "\nVeiculo " + Menssagens.itemObrigatorio;
		}

		double quilometragem = 0.0;
		if (!cndQuilometragem.getText().equals(""))
		{
			quilometragem = Double.parseDouble(cndQuilometragem.getNumero());

			if (quilometragem == 0)
			{
				mensagem += "\nQuilometragem " + Menssagens.itemObrigatorio;
			}
		}

		Date dataSaida = jdcDataSaida.getDate();
		if (dataSaida == null)
		{
			mensagem += "\nData Saída " + Menssagens.itemObrigatorio;
		}

		Date dataDevolucaoPrevista = jdcDataDevolucaoPrevista.getDate();
		if (dataDevolucaoPrevista == null)
		{
			mensagem += "\nData Devolucao Prevista "
					+ Menssagens.itemObrigatorio;
		}

		if (dataDevolucaoPrevista.getTime() <= dataSaida.getTime())
		{
			mensagem += "\nData Devolucao Prevista deve ser maior que a Data de Saída!";
		}

		double valorDiaria = 0.0;
		if (!cndValorDiaria.getText().equals(""))
		{
			valorDiaria = Double.parseDouble(cndValorDiaria.getNumero());
		}

		double valorMotoristaExtra = 0.0;
		if (cndValorMotoristaExtra.getText().equals(""))
		{
			valorMotoristaExtra = 0.0;
		} else
		{
			valorMotoristaExtra = Double.parseDouble(cndValorMotoristaExtra
					.getNumero());
		}

		double valorFranquia = 0.0;
		if (!cndFranquia.getText().equals(""))
		{
			valorFranquia = Double.parseDouble(cndFranquia.getNumero());
		}
		
		String formaPagamento = (String)cgFormaPagamento.getSelectedItem();
		
		String observacao = ctObservacao.getText();

		if (mensagem.equals(""))
		{
			aluguel.setPosicaoAluguel(posicaoAluguel);
			aluguel.setCliente(cliente);
			aluguel.setVeiculo(veiculo);
			veiculo.setQuilometragem(quilometragem);
			aluguel.setDataSaida(dataSaida);
			aluguel.setDataDevolucaoPrevista(dataDevolucaoPrevista);
			aluguel.setValorDiaria(valorDiaria);
			aluguel.setValorMotoristaExtra(valorMotoristaExtra);
			aluguel.setValorFranquia(valorFranquia);
			aluguel.setFormaPagamento(formaPagamento);
			aluguel.setObservacao(observacao);

		} else
		{
			throw new Exception(mensagem);
		}
	}

	@Override
	public void preencherFormulario() throws Exception
	{
		Aluguel aluguel = (Aluguel) getObjDados();

		cgSituacao.setObjetoCorrente(aluguel.getPosicaoAluguel());
		cplCliente.setObjeto(aluguel.getCliente());
		cplVeiculo.setObjeto(aluguel.getVeiculo());
		cndQuilometragem.setText(String.valueOf(aluguel.getVeiculo()
				.getQuilometragem()));
		jdcDataSaida.setDate(aluguel.getDataSaida());
		jdcDataDevolucaoPrevista.setDate(aluguel.getDataDevolucaoPrevista());
		jdcDataDevolucaoReal.setDate(aluguel.getDataDevolucaoReal());
		cndValorDiaria.setText(String.valueOf(aluguel.getValorDiaria()));
		cndValorMotoristaExtra.setText(String.valueOf(aluguel
				.getValorMotoristaExtra()));
		cndFranquia.setText(String.valueOf(aluguel.getValorFranquia()));

		preencheTabelaMotoristas();
		preencheTabelaCustos();
		
		cgFormaPagamento.setSelectedItem(aluguel.getFormaPagamento());
		ctObservacao.setText(aluguel.getObservacao());

		calcular();
	}

	private void preencheTabelaMotoristas() throws Exception
	{
		Aluguel aluguel = (Aluguel) getObjDados();

		Set<IObjetoSistema> motoristas = new HashSet<IObjetoSistema>();

		for (MotoristaAdicional motorista : aluguel.getMotoristas())
		{
			motoristas.add(motorista);
		}

		tblMotoristas.setDados(motoristas);
		tblMotoristas.setColunas(colunasTabelaMotoristas());
		tblMotoristas.bind();
	}

	private ArrayList<String[]> colunasTabelaMotoristas()
	{
		ArrayList<String[]> dscColunas = new ArrayList<String[]>();
		dscColunas.add(new String[]
		{ "CNH", "getCnh" });
		dscColunas.add(new String[]
		{ "Motorista", "getNome", "300" });

		return dscColunas;
	}

	private ArrayList<String[]> formatarGridPesquisaCliente()
	{
		ArrayList<String[]> descricaoColunas = new ArrayList<String[]>();
		descricaoColunas.add(new String[]
		{ "Cliente", "getNome", "300" });
		descricaoColunas.add(new String[]
		{ "CPF", "getCpf" });

		return descricaoColunas;
	}

	private ArrayList<String[]> formatarGridPesquisaVeiculo()
	{
		ArrayList<String[]> descricaoColunas = new ArrayList<String[]>();
		descricaoColunas.add(new String[]
		{ "Placa", "getPlaca" });
		descricaoColunas.add(new String[]
		{ "Veiculo", "getNome", "300" });

		return descricaoColunas;
	}

	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents()
	{

		pnlPrincipal = new telas.componentes.Painel();
		botBotoes = new telas.componentes.BarraOperacoesTela();
		jTabbedPane1 = new javax.swing.JTabbedPane();
		pnlCadastro = new telas.componentes.Painel();
		rotulo1 = new telas.componentes.Rotulo();
		cgSituacao = new telas.componentes.ComboGeral();
		rotulo2 = new telas.componentes.Rotulo();
		cplCliente = new telas.componentes.CampoPopupLocalizador();
		btNovoCliente = new telas.componentes.Botao();
		rotulo3 = new telas.componentes.Rotulo();
		cplVeiculo = new telas.componentes.CampoPopupLocalizador();
		rotulo4 = new telas.componentes.Rotulo();
		jdcDataSaida = new com.toedter.calendar.JDateChooser();
		rotulo5 = new telas.componentes.Rotulo();
		jdcDataDevolucaoPrevista = new com.toedter.calendar.JDateChooser();
		rotulo6 = new telas.componentes.Rotulo();
		jdcDataDevolucaoReal = new com.toedter.calendar.JDateChooser();
		rotulo9 = new telas.componentes.Rotulo();
		cndCustoTotal = new telas.componentes.CampoNumeroDecimal();
		btCalcular = new telas.componentes.Botao();
		ptFinalizarContrato = new telas.componentes.Botao();
		rotulo11 = new telas.componentes.Rotulo();
		cniDiarias = new telas.componentes.CampoNumeroInteiro();
		cndValorDiaria = new telas.componentes.CampoNumeroDecimal();
		rotulo12 = new telas.componentes.Rotulo();
		rotulo14 = new telas.componentes.Rotulo();
		cndValorTotalDiarias = new telas.componentes.CampoNumeroDecimal();
		rotulo16 = new telas.componentes.Rotulo();
		cndQuilometragem = new telas.componentes.CampoNumeroDecimal();
		pnlMotoristas = new telas.componentes.Painel();
		jScrollPane1 = new javax.swing.JScrollPane();
		tblMotoristas = new telas.componentes.Tabela();
		rotulo7 = new telas.componentes.Rotulo();
		btAdicionarMotorista = new telas.componentes.Botao();
		btCadastrarNovoMotorista = new telas.componentes.Botao();
		btRemoverMotorista = new telas.componentes.Botao();
		rotulo10 = new telas.componentes.Rotulo();
		cndValorMotoristaExtra = new telas.componentes.CampoNumeroDecimal();
		rotulo13 = new telas.componentes.Rotulo();
		cndTotalMotoristas = new telas.componentes.CampoNumeroDecimal();
		pnlCustos = new telas.componentes.Painel();
		jScrollPane2 = new javax.swing.JScrollPane();
		tblCustos = new telas.componentes.Tabela();
		rotulo8 = new telas.componentes.Rotulo();
		btAdicionarCusto = new telas.componentes.Botao();
		btRemoverCusto = new telas.componentes.Botao();
		rotulo15 = new telas.componentes.Rotulo();
		cndFranquia = new telas.componentes.CampoNumeroDecimal();
		pnlPagamento = new telas.componentes.Painel();
		rotulo17 = new telas.componentes.Rotulo();
		cgFormaPagamento = new telas.componentes.ComboGeral();
		rotulo18 = new telas.componentes.Rotulo();
		ctObservacao = new telas.componentes.CampoTexto();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		pnlPrincipal.setLayout(new java.awt.BorderLayout());
		pnlPrincipal.add(botBotoes, java.awt.BorderLayout.PAGE_END);

		pnlCadastro.setBorder(javax.swing.BorderFactory
				.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

		rotulo1.setText("Situa\u00e7\u00e3o:");

		cgSituacao.setModel(new javax.swing.DefaultComboBoxModel(new String[]
		{ "Selecione" }));
		cgSituacao.setEnabled(false);
		cgSituacao.setMetodoDescricao("getNome");
		cgSituacao.setMetodoIdentificador("getCodigo");
		cgSituacao.setDataSource(posicaoAluguel.obterTodos());

		rotulo2.setText("Cliente:");

		cplCliente.setAtributoVisualizacao("Nome");
		cplCliente.setCampoPesquisa("nome");
		cplCliente.setClassePesquisa("business.aluguel.Cliente");
		cplCliente.setDescricaoPesquisa("Nome:");
		cplCliente.setFormatoGridPesquisa(formatarGridPesquisaCliente());

		btNovoCliente.setText("Novo");
		btNovoCliente.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(java.awt.event.ActionEvent evt)
			{
				btNovoClienteActionPerformed(evt);
			}
		});

		rotulo3.setText("Veiculo:");

		cplVeiculo.setAtributoVisualizacao("Nome");
		cplVeiculo.setCampoPesquisa("placa");
		cplVeiculo.setClassePesquisa("business.aluguel.Veiculo");
		cplVeiculo.setDescricaoPesquisa("Placa:");
		cplVeiculo.setFormatoGridPesquisa(formatarGridPesquisaVeiculo());
		cplVeiculo.registerObserver(cndValorDiaria);
		cplVeiculo.registerObserver(cndQuilometragem);

		rotulo4.setText("Sa\u00edda:");

		jdcDataSaida.setDateFormatString("dd/MM/yyyy HH:mm");

		rotulo5.setText("Devolu\u00e7\u00e3o Prevista:");

		jdcDataDevolucaoPrevista.setDateFormatString("dd/MM/yyyy HH:mm");

		rotulo6.setText("Devolu\u00e7\u00e3o:");

		jdcDataDevolucaoReal.setDateFormatString("dd/MM/yyyy HH:mm");
		jdcDataDevolucaoReal.setEnabled(false);

		rotulo9.setText("Total:");

		cndCustoTotal.setFont(new java.awt.Font("Dialog", 1, 12));

		btCalcular.setText("Calcular");
		btCalcular.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(java.awt.event.ActionEvent evt)
			{
				btCalcularActionPerformed(evt);
			}
		});

		ptFinalizarContrato.setText("Finalizar");
		ptFinalizarContrato
				.addActionListener(new java.awt.event.ActionListener()
				{
					public void actionPerformed(java.awt.event.ActionEvent evt)
					{
						ptFinalizarContratoActionPerformed(evt);
					}
				});

		rotulo11.setText("Di\u00e1rias:");

		cniDiarias.setEditable(false);

		cndValorDiaria.setAtributoObservado("ValorAluguel");

		rotulo12.setText("Valor:     ");

		rotulo14.setText("Tot. Diar.:");

		rotulo16.setText("KM:");

		cndQuilometragem.setAtributoObservado("Quilometragem");

		javax.swing.GroupLayout pnlCadastroLayout = new javax.swing.GroupLayout(
				pnlCadastro);
		pnlCadastro.setLayout(pnlCadastroLayout);
		pnlCadastroLayout
				.setHorizontalGroup(pnlCadastroLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								pnlCadastroLayout
										.createSequentialGroup()
										.addGap(12, 12, 12)
										.addComponent(
												rotulo3,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(729, Short.MAX_VALUE))
						.addGroup(
								pnlCadastroLayout
										.createSequentialGroup()
										.addGroup(
												pnlCadastroLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																pnlCadastroLayout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addGroup(
																				pnlCadastroLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								rotulo4,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								rotulo11,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								rotulo12,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								rotulo14,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								rotulo9,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)))
														.addGroup(
																pnlCadastroLayout
																		.createSequentialGroup()
																		.addGap(
																				12,
																				12,
																				12)
																		.addGroup(
																				pnlCadastroLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								rotulo1,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								rotulo2,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)))
														.addGroup(
																pnlCadastroLayout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				rotulo16,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)))
										.addGap(7, 7, 7)
										.addGroup(
												pnlCadastroLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																pnlCadastroLayout
																		.createSequentialGroup()
																		.addGap(
																				1,
																				1,
																				1)
																		.addGroup(
																				pnlCadastroLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addGroup(
																								pnlCadastroLayout
																										.createSequentialGroup()
																										.addGroup(
																												pnlCadastroLayout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.TRAILING)
																														.addComponent(
																																cplVeiculo,
																																javax.swing.GroupLayout.Alignment.LEADING,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																603,
																																Short.MAX_VALUE)
																														.addGroup(
																																pnlCadastroLayout
																																		.createSequentialGroup()
																																		.addPreferredGap(
																																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																																		.addComponent(
																																				cplCliente,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				603,
																																				Short.MAX_VALUE)))
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED))
																						.addGroup(
																								pnlCadastroLayout
																										.createSequentialGroup()
																										.addComponent(
																												cgSituacao,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												145,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addGap(
																												451,
																												451,
																												451)))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				btNovoCliente,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				81,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addGap(
																				21,
																				21,
																				21))
														.addGroup(
																pnlCadastroLayout
																		.createSequentialGroup()
																		.addGroup(
																				pnlCadastroLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								cniDiarias,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								43,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addGroup(
																								pnlCadastroLayout
																										.createSequentialGroup()
																										.addComponent(
																												jdcDataSaida,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												159,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																												26,
																												Short.MAX_VALUE)
																										.addComponent(
																												rotulo5,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												javax.swing.GroupLayout.DEFAULT_SIZE,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												jdcDataDevolucaoPrevista,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												161,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addGap(
																												18,
																												18,
																												18)
																										.addComponent(
																												rotulo6,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												javax.swing.GroupLayout.DEFAULT_SIZE,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												jdcDataDevolucaoReal,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												149,
																												javax.swing.GroupLayout.PREFERRED_SIZE))
																						.addGroup(
																								pnlCadastroLayout
																										.createSequentialGroup()
																										.addGroup(
																												pnlCadastroLayout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.TRAILING,
																																false)
																														.addComponent(
																																cndCustoTotal,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																Short.MAX_VALUE)
																														.addComponent(
																																cndValorDiaria,
																																javax.swing.GroupLayout.Alignment.LEADING,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																Short.MAX_VALUE)
																														.addComponent(
																																cndValorTotalDiarias,
																																javax.swing.GroupLayout.Alignment.LEADING,
																																javax.swing.GroupLayout.PREFERRED_SIZE,
																																106,
																																javax.swing.GroupLayout.PREFERRED_SIZE))
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												btCalcular,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												96,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												ptFinalizarContrato,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												109,
																												javax.swing.GroupLayout.PREFERRED_SIZE)))
																		.addContainerGap())
														.addGroup(
																pnlCadastroLayout
																		.createSequentialGroup()
																		.addComponent(
																				cndQuilometragem,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				106,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addContainerGap()))));
		pnlCadastroLayout
				.setVerticalGroup(pnlCadastroLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								pnlCadastroLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												pnlCadastroLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																rotulo1,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																cgSituacao,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGroup(
												pnlCadastroLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																pnlCadastroLayout
																		.createSequentialGroup()
																		.addGap(
																				18,
																				18,
																				18)
																		.addComponent(
																				rotulo2,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE))
														.addGroup(
																pnlCadastroLayout
																		.createSequentialGroup()
																		.addGap(
																				9,
																				9,
																				9)
																		.addGroup(
																				pnlCadastroLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								btNovoCliente,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								cplCliente,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))))
										.addGroup(
												pnlCadastroLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																pnlCadastroLayout
																		.createSequentialGroup()
																		.addGap(
																				19,
																				19,
																				19)
																		.addComponent(
																				rotulo3,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE))
														.addGroup(
																pnlCadastroLayout
																		.createSequentialGroup()
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				cplVeiculo,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pnlCadastroLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.CENTER)
														.addComponent(
																cndQuilometragem,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																rotulo16,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pnlCadastroLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.CENTER)
														.addComponent(
																rotulo4,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																jdcDataSaida,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																jdcDataDevolucaoPrevista,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																rotulo5,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																jdcDataDevolucaoReal,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																rotulo6,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pnlCadastroLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																rotulo11,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																cniDiarias,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pnlCadastroLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																rotulo12,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																cndValorDiaria,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pnlCadastroLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																rotulo14,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																cndValorTotalDiarias,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pnlCadastroLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																rotulo9,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																cndCustoTotal,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btCalcular,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																ptFinalizarContrato,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addContainerGap(23, Short.MAX_VALUE)));

		jTabbedPane1.addTab("Contrato", pnlCadastro);

		pnlMotoristas.setBorder(javax.swing.BorderFactory
				.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

		tblMotoristas.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][]
				{

				}, new String[]
				{

				}));
		jScrollPane1.setViewportView(tblMotoristas);

		rotulo7.setText("Motoristas");

		btAdicionarMotorista.setText("Adicionar");
		btAdicionarMotorista
				.addActionListener(new java.awt.event.ActionListener()
				{
					public void actionPerformed(java.awt.event.ActionEvent evt)
					{
						btAdicionarMotoristaActionPerformed(evt);
					}
				});

		btCadastrarNovoMotorista.setText("Novo");
		btCadastrarNovoMotorista
				.addActionListener(new java.awt.event.ActionListener()
				{
					public void actionPerformed(java.awt.event.ActionEvent evt)
					{
						btCadastrarNovoMotoristaActionPerformed(evt);
					}
				});

		btRemoverMotorista.setText("Remover");
		btRemoverMotorista
				.addActionListener(new java.awt.event.ActionListener()
				{
					public void actionPerformed(java.awt.event.ActionEvent evt)
					{
						btRemoverMotoristaActionPerformed(evt);
					}
				});

		rotulo10.setText("Valor p/ Motorista:");

		rotulo13.setText("Total:");

		cndTotalMotoristas.setEditable(false);
		cndTotalMotoristas.setFont(new java.awt.Font("Dialog", 1, 12));

		javax.swing.GroupLayout pnlMotoristasLayout = new javax.swing.GroupLayout(
				pnlMotoristas);
		pnlMotoristas.setLayout(pnlMotoristasLayout);
		pnlMotoristasLayout
				.setHorizontalGroup(pnlMotoristasLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								pnlMotoristasLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												pnlMotoristasLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																jScrollPane1,
																javax.swing.GroupLayout.Alignment.TRAILING,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																750,
																Short.MAX_VALUE)
														.addGroup(
																pnlMotoristasLayout
																		.createSequentialGroup()
																		.addComponent(
																				rotulo7,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				btAdicionarMotorista,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				107,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				btCadastrarNovoMotorista,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				100,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				btRemoverMotorista,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				105,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				rotulo10,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				cndValorMotoristaExtra,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				68,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				rotulo13,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				cndTotalMotoristas,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				86,
																				Short.MAX_VALUE)))
										.addGap(21, 21, 21)));
		pnlMotoristasLayout
				.setVerticalGroup(pnlMotoristasLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								pnlMotoristasLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												pnlMotoristasLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																rotulo7,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btAdicionarMotorista,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btCadastrarNovoMotorista,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btRemoverMotorista,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																rotulo10,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																cndValorMotoristaExtra,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																rotulo13,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																cndTotalMotoristas,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(
												jScrollPane1,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												244, Short.MAX_VALUE)
										.addContainerGap()));

		jTabbedPane1.addTab("Motoristas", pnlMotoristas);

		pnlCustos.setBorder(javax.swing.BorderFactory
				.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

		tblCustos.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][]
				{

				}, new String[]
				{

				}));
		jScrollPane2.setViewportView(tblCustos);

		rotulo8.setText("Custos");

		btAdicionarCusto.setText("Adicionar");
		btAdicionarCusto.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(java.awt.event.ActionEvent evt)
			{
				btAdicionarCustoActionPerformed(evt);
			}
		});

		btRemoverCusto.setText("Remover");
		btRemoverCusto.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(java.awt.event.ActionEvent evt)
			{
				btRemoverCustoActionPerformed(evt);
			}
		});

		rotulo15.setText("Franquia:");

		javax.swing.GroupLayout pnlCustosLayout = new javax.swing.GroupLayout(
				pnlCustos);
		pnlCustos.setLayout(pnlCustosLayout);
		pnlCustosLayout
				.setHorizontalGroup(pnlCustosLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								pnlCustosLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												pnlCustosLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																pnlCustosLayout
																		.createSequentialGroup()
																		.addComponent(
																				rotulo8,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				btAdicionarCusto,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				107,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addComponent(
																				btRemoverCusto,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				114,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addContainerGap())
														.addGroup(
																pnlCustosLayout
																		.createSequentialGroup()
																		.addComponent(
																				jScrollPane2,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				754,
																				Short.MAX_VALUE)
																		.addGap(
																				17,
																				17,
																				17))
														.addGroup(
																pnlCustosLayout
																		.createSequentialGroup()
																		.addComponent(
																				rotulo15,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				cndFranquia,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				103,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addContainerGap()))));
		pnlCustosLayout
				.setVerticalGroup(pnlCustosLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								pnlCustosLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												pnlCustosLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																rotulo8,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btAdicionarCusto,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btRemoverCusto,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jScrollPane2,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												118,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												110, Short.MAX_VALUE)
										.addGroup(
												pnlCustosLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																rotulo15,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																cndFranquia,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addContainerGap()));

		jTabbedPane1.addTab("Custos", pnlCustos);

		rotulo17.setText("Forma de Pagamento:");

		cgFormaPagamento.setModel(new javax.swing.DefaultComboBoxModel(
				new String[]
				{ "A vista", "Boleto", "Cartão", "Cheque" }));

		rotulo18.setText("Observa\u00e7\u00e3o:");

		ctObservacao.setMaxLength(100);

		javax.swing.GroupLayout pnlPagamentoLayout = new javax.swing.GroupLayout(
				pnlPagamento);
		pnlPagamento.setLayout(pnlPagamentoLayout);
		pnlPagamentoLayout
				.setHorizontalGroup(pnlPagamentoLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								pnlPagamentoLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												pnlPagamentoLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																rotulo17,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																rotulo18,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pnlPagamentoLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																cgFormaPagamento,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																211,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																ctObservacao,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																636,
																Short.MAX_VALUE))
										.addContainerGap()));
		pnlPagamentoLayout
				.setVerticalGroup(pnlPagamentoLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								pnlPagamentoLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												pnlPagamentoLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																rotulo17,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																cgFormaPagamento,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addGroup(
												pnlPagamentoLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																rotulo18,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																ctObservacao,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addContainerGap(238, Short.MAX_VALUE)));

		jTabbedPane1.addTab("Pagamento", pnlPagamento);

		pnlPrincipal.add(jTabbedPane1, java.awt.BorderLayout.CENTER);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				pnlPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 792,
				Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				pnlPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 363,
				Short.MAX_VALUE));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	private void ptFinalizarContratoActionPerformed(
			java.awt.event.ActionEvent evt)
	{
		try
		{
			Aluguel aluguel = (Aluguel) getObjDados();

			preencheObjeto();

			aluguel.finalizar();

			jdcDataDevolucaoReal.setDate(aluguel.getDataDevolucaoReal());
			cgSituacao.setObjetoCorrente(aluguel.getPosicaoAluguel());

			verificarPosicaoAluguel();

			calcular();
		} catch (Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	private void btCalcularActionPerformed(java.awt.event.ActionEvent evt)
	{
		try
		{
			calcular();
		} catch (Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	private void calcular() throws Exception
	{
		Aluguel aluguel = (Aluguel) getObjDados();

		preencheObjeto();

		cndCustoTotal.setText(String.valueOf(aluguel.calcular()));
		cniDiarias.setText(String.valueOf(aluguel.getDiarias()));
		cndValorTotalDiarias.setText(String.valueOf(aluguel
				.getValorTotalDiarias()));
		cndTotalMotoristas.setText(String.valueOf(aluguel
				.getValorTotalMotoristaExtra()));
	}

	private void btRemoverCustoActionPerformed(java.awt.event.ActionEvent evt)
	{
		try
		{
			Custo custo = (Custo) tblCustos.getObjetoCorrente();

			((Aluguel) getObjDados()).removerCusto(custo);

			preencheTabelaCustos();

			calcular();
		} catch (Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	private void btAdicionarCustoActionPerformed(java.awt.event.ActionEvent evt)
	{
		try
		{
			Aluguel aluguel = (Aluguel) getObjDados();
			Custo custo = new Custo();
			new TelaAluguelCadastroCusto(custo, true);

			if (custo != null && custo.getProduto() != null
					&& custo.getProduto().getCodigo() != 0)
			{

				// Adiciona o custo e se ja estiver cadastrado informa
				// ao usuário que o custo ja foi cadastrado,
				// não alterando o estado atual do custo adicionado anteriormente.
				if (aluguel.addCusto(custo))
				{
					JOptionPane.showMessageDialog(this, "Custo: "
							+ custo.getProduto().getNome() + " - "
							+ Menssagens.objetoCadastrado);
				}

				preencheTabelaCustos();

				calcular();
			}

		} catch (Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	private void preencheTabelaCustos() throws Exception
	{
		Aluguel aluguel = (Aluguel) getObjDados();

		Set<IObjetoSistema> custos = new HashSet<IObjetoSistema>();

		if (aluguel.getCustos() != null)
		{
			for (Custo custo : aluguel.getCustos())
			{
				custos.add(custo);
			}
		}

		tblCustos.setDados(custos);
		tblCustos.setColunas(colunasTabelaCustos());
		tblCustos.bind();
	}

	private ArrayList<String[]> colunasTabelaCustos()
	{
		ArrayList<String[]> dscColunas = new ArrayList<String[]>();
		dscColunas.add(new String[]
		{ "Produto", "getNome", "300" });
		dscColunas.add(new String[]
		{ "Quantidade", "getQuantidade" });
		dscColunas.add(new String[]
		{ "Valor", "getValor" });
		dscColunas.add(new String[]
		{ "Total", "getCustoTotal" });

		return dscColunas;
	}

	private void btRemoverMotoristaActionPerformed(
			java.awt.event.ActionEvent evt)
	{
		try
		{
			MotoristaAdicional motorista = (MotoristaAdicional) tblMotoristas
					.getObjetoCorrente();

			((Aluguel) getObjDados()).removeMotorista(motorista);

			preencheTabelaMotoristas();

			calcular();
		} catch (Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	private void btCadastrarNovoMotoristaActionPerformed(
			java.awt.event.ActionEvent evt)
	{
		try
		{
			Cliente motorista = new Cliente();

			new TelaClienteCadastro(motorista, true);

			adicionarMotorista(motorista);

			calcular();
		} catch (Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	private void btAdicionarMotoristaActionPerformed(
			java.awt.event.ActionEvent evt)
	{
		try
		{
			Cliente motorista = new Cliente();

			Localizador localizador = new Localizador(motorista, "cnh",
					formatarGridPesquisaMotorista(), "CNH:", null, "");

			IObjetoSistema objetoSelecionado = localizador.obterSelecionado();

			motorista = (Cliente) objetoSelecionado;

			if (motorista != null && motorista.getCodigo() != 0)
			{
				adicionarMotorista(motorista);

				calcular();
			}

		} catch (Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	private void adicionarMotorista(Cliente motorista) throws Exception
	{
		if (motorista != null)
		{
			if (((Aluguel) getObjDados()).addMotorista(motorista))
			{
				JOptionPane.showMessageDialog(this, "Motorista "
						+ Menssagens.objetoCadastrado);
			}

			preencheTabelaMotoristas();
		}
	}

	private ArrayList<String[]> formatarGridPesquisaMotorista()
	{
		ArrayList<String[]> descricaoColunas = new ArrayList<String[]>();
		descricaoColunas.add(new String[]
		{ "CNH", "getCnh" });
		descricaoColunas.add(new String[]
		{ "Motorista", "getNome", "300" });

		return descricaoColunas;
	}

	private void btNovoClienteActionPerformed(java.awt.event.ActionEvent evt)
	{
		try
		{
			Cliente cliente = new Cliente();

			new TelaClienteCadastro(cliente, true);

			cplCliente.setObjeto(cliente);
		} catch (Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private telas.componentes.BarraOperacoesTela botBotoes;
	private telas.componentes.Botao btAdicionarCusto;
	private telas.componentes.Botao btAdicionarMotorista;
	private telas.componentes.Botao btCadastrarNovoMotorista;
	private telas.componentes.Botao btCalcular;
	private telas.componentes.Botao btNovoCliente;
	private telas.componentes.Botao btRemoverCusto;
	private telas.componentes.Botao btRemoverMotorista;
	private telas.componentes.ComboGeral cgFormaPagamento;
	private telas.componentes.ComboGeral cgSituacao;
	private telas.componentes.CampoNumeroDecimal cndCustoTotal;
	private telas.componentes.CampoNumeroDecimal cndFranquia;
	private telas.componentes.CampoNumeroDecimal cndQuilometragem;
	private telas.componentes.CampoNumeroDecimal cndTotalMotoristas;
	private telas.componentes.CampoNumeroDecimal cndValorDiaria;
	private telas.componentes.CampoNumeroDecimal cndValorMotoristaExtra;
	private telas.componentes.CampoNumeroDecimal cndValorTotalDiarias;
	private telas.componentes.CampoNumeroInteiro cniDiarias;
	private telas.componentes.CampoPopupLocalizador cplCliente;
	private telas.componentes.CampoPopupLocalizador cplVeiculo;
	private telas.componentes.CampoTexto ctObservacao;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JScrollPane jScrollPane2;
	private javax.swing.JTabbedPane jTabbedPane1;
	private com.toedter.calendar.JDateChooser jdcDataDevolucaoPrevista;
	private com.toedter.calendar.JDateChooser jdcDataDevolucaoReal;
	private com.toedter.calendar.JDateChooser jdcDataSaida;
	private telas.componentes.Painel pnlCadastro;
	private telas.componentes.Painel pnlCustos;
	private telas.componentes.Painel pnlMotoristas;
	private telas.componentes.Painel pnlPagamento;
	private telas.componentes.Painel pnlPrincipal;
	private telas.componentes.Botao ptFinalizarContrato;
	private telas.componentes.Rotulo rotulo1;
	private telas.componentes.Rotulo rotulo10;
	private telas.componentes.Rotulo rotulo11;
	private telas.componentes.Rotulo rotulo12;
	private telas.componentes.Rotulo rotulo13;
	private telas.componentes.Rotulo rotulo14;
	private telas.componentes.Rotulo rotulo15;
	private telas.componentes.Rotulo rotulo16;
	private telas.componentes.Rotulo rotulo17;
	private telas.componentes.Rotulo rotulo18;
	private telas.componentes.Rotulo rotulo2;
	private telas.componentes.Rotulo rotulo3;
	private telas.componentes.Rotulo rotulo4;
	private telas.componentes.Rotulo rotulo5;
	private telas.componentes.Rotulo rotulo6;
	private telas.componentes.Rotulo rotulo7;
	private telas.componentes.Rotulo rotulo8;
	private telas.componentes.Rotulo rotulo9;
	private telas.componentes.Tabela tblCustos;
	private telas.componentes.Tabela tblMotoristas;
	// End of variables declaration//GEN-END:variables

	PosicaoAluguel posicaoAluguel = new PosicaoAluguel();

}